package ${package.Controller};

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ${package.Service}.${table.serviceName};
import ${package.Entity}.${entity};
import com.wendy.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
<#if restControllerStyle>
 import org.springframework.web.bind.annotation.RestController;
<#else>
 import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
 import ${superControllerClassPackage};
</#if>

/**
* <p>
 * ${table.comment!} 前端控制器
 * </p>
*
* @author ${author}
* @since ${date}
*/
@Slf4j
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@Api(tags = "${table.comment!}")
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if><#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}/</#if>")
<#if kotlin>
 class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
 <#if superControllerClass??>
  public class ${table.controllerName} extends ${superControllerClass} {
 <#else>
  public class ${table.controllerName} {

  @Resource
  public ${table.serviceName} ${table.entityPath}Service;

  @GetMapping("/pageList")
  @ApiOperation(value = "分页查询列表")
  public R<?> pageList(@RequestParam(value = "pageNum", defaultValue = "1") Long pageNum,
                            @RequestParam(value = "pageSize", defaultValue = "10") Long pageSize) {

    IPage<${entity}> page = ${table.entityPath}Service.page(new Page<>(pageNum, pageSize), null);
    return R.ok(page, "查询成功");
  }

  @PostMapping("/get")
  @ApiOperation(value = "条件查询")
  public R<?> list(@RequestBody ${entity} ${table.entityPath}) {
    List<${entity}> ${table.entityPath}List = ${table.entityPath}Service.list(new QueryWrapper<>(${table.entityPath}));
    return R.ok(${table.entityPath}List, "查询成功");
  }

  @GetMapping("/get/{id}")
  @ApiOperation(value = "根据id查详情")
  public R<?> get(@PathVariable("id") String id) {
    ${entity} ${table.entityPath} = ${table.entityPath}Service.getById(id);
    return R.ok(${table.entityPath}, "查询成功");
  }

  @PostMapping("/save")
  @ApiOperation(value = "新增")
  public R<?> save(@RequestBody ${entity} ${table.entityPath}) {
    ${table.entityPath}Service.save(${table.entityPath});
    return R.ok("保存成功");
  }

  @PostMapping("/delete/{id}")
  @ApiOperation(value = "根据id删除")
  public R<?> delete(@PathVariable("id") Long id) {
    ${table.entityPath}Service.removeById(id);
    return R.ok("删除成功");
  }

  @PostMapping("/update")
  @ApiOperation(value = "根据id修改")
  public R<?> update(@RequestBody ${entity} ${table.entityPath}) {
    ${table.entityPath}Service.updateById(${table.entityPath});
    return R.ok("更新成功");
  }

 </#if>
}
</#if>